package game;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import level.LevelDownloader;

/**
 * 
 * @author Jevgeni Krutov
 *
 */
public class Menu extends JFrame {
	private static final long serialVersionUID = -2135190122896866375L;

	public Menu() {
		JPanel panel = new JPanel();
		getContentPane().add(panel);

		panel.setLayout(null);

		List<String> levels = LevelDownloader.getLevelList();
		
		int i = 0;
		for(final String level : levels) {
			JButton button = new JButton();
			button.setText(level.substring(0, level.length()-4));
			button.setBounds(10, 10 + 25*i++, 270, 20);
			
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent event) {
					new Game(level);
					System.exit(0);
				}
			});
			panel.add(button);
		}

		setTitle("4D Game levels");
		setSize(300, 700);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
	}

	public static void main(String[] args) {
	  	new Menu();
    }
}